﻿@using SimplCommerce.Infrastructure.Data
@using SimplCommerce.Module.Core.Models
@using SimplCommerce.Module.Core.Services

@model SimplCommerce.Module.Orders.Models.Order
@inject IRepository<StateOrProvince> StateOrProvinceRepository
@inject IRepository<District> DistrictRepository
@inject ICurrencyService CurrencyService


@{
    var shippingStateOrProvince = StateOrProvinceRepository.Query().First(x => x.Id == Model.ShippingAddress.StateOrProvinceId);
    string shippingDistrictName = "";
    if (Model.ShippingAddress.DistrictId.HasValue)
    {
        var district = DistrictRepository.Query().FirstOrDefault(x => x.Id == Model.ShippingAddress.DistrictId.Value);
        shippingDistrictName = $"{district.Name}, ";
    }
}

@{
    Layout = null;
}

<table border="0" cellpadding="0" cellspacing="0" style="background:#ffffff;width:100%">
    <tbody>
        <tr>
            <td align="center" valign="top">
                <table border="0" cellpadding="0" cellspacing="0" style="width:650px;border-top:1px #cccccc">
                    <tbody>
                        <tr>
                            <td align="left" style="font-family:Arial,Helvetica,sans-serif;font-size:12px;color:#333333;background:#fff" valign="top">
                                <h1>Congratulation, Your order is received</h1>
                                <p>Dear <strong>@Model.CreatedBy.FullName</strong>,</p>
                                <p>Quý khách đã đặt hàng thành công với thông tin đơn hàng như sau:</p>
                                <p></p>
                                <div style="background:#eff0f4;border:1px solid #e2e2e2;margin-top:10px;width:100%">
                                    <table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" style="width:100%">
                                        <tbody>
                                            <tr style="padding:10px">
                                                <td colspan="2" style="border-top:1px solid #eff0f4">
                                                    <table style="padding:7px 0">
                                                        <tbody>
                                                            <tr>
                                                                <td style="padding:2px 8px 0px 15px">@Localizer["Order No."]:</td>
                                                                <td style="padding:2px 8px 0px 15px"><strong>@Model.Id</strong></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="padding: 2px 8px 0px 15px">@Localizer["Order Date"]:</td>
                                                                <td style="padding: 2px 8px 0px 15px"><strong>@Model.CreatedOn</strong></td>
                                                            </tr>
                                                            <tr>
                                                                <td style="padding: 2px 8px 0px 15px" valign="top">@Localizer["Shippping Address"]:</td>
                                                                <td style="padding: 2px 8px 0px 15px">
                                                                    <strong>@Model.ShippingAddress.ContactName </strong><br />
                                                                    @Model.ShippingAddress.AddressLine1 <br />
                                                                    @shippingDistrictName @shippingStateOrProvince.Name<br />
                                                                    Phone: @Model.ShippingAddress.Phone
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td style="padding: 2px 8px 0px 15px">@Localizer["Order Status"]:</td>
                                                                <td style="padding: 2px 8px 0px 15px; color: green">@Model.OrderStatus</td>
                                                            </tr>
                                                        </tbody>
                                                    </table>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <div style="background:#eff0f4;border:1px solid #e2e2e2;margin-top:10px;width:100%">
                                    <table bgcolor="#FFFFFF" border="0" cellpadding="0" cellspacing="0" style="width:100%">
                                        <tbody>
                                            <tr bgcolor="#cc0000" style="color:#fff;height:25px">
                                                <th scope="col" style="padding:5px">@Localizer["Products"]</th>
                                                <th scope="col" style="padding:5px">@Localizer["Price"]</th>
                                                <th scope="col" style="padding:5px">@Localizer["Quantity"]</th>
                                                <th scope="col" style="padding:5px">@Localizer["Total"]</th>
                                            </tr>
                                            @foreach (var item in Model.OrderItems)
                                            {
                                                <tr>
                                                    <td style="padding:5px 0 5px 15px">
                                                        <div>@item.Product.Name</div>
                                                    </td>
                                                    <td style="padding:5px 0;text-align:right">@CurrencyService.FormatCurrency(item.ProductPrice)</td>
                                                    <td style="padding:5px 0;text-align:center">@item.Quantity</td>
                                                    <td style="padding:5px 15px 5px 0px;text-align:right">@CurrencyService.FormatCurrency(item.ProductPrice * item.Quantity))</td>
                                                </tr>
                                            }
                                            <tr>
                                                <td align="right" colspan="3" style="border-top:1px solid #eff0f4;border-bottom:1px solid #eff0f4;padding:5px">@Localizer["Discount"]</td>
                                                <td align="right" style="border-top:1px solid #eff0f4;border-bottom:1px solid #eff0f4;padding:5px 16px 5px 5px">@CurrencyService.FormatCurrency(Model.DiscountAmount)</td>
                                            </tr>
                                            <tr>
                                                <td align="right" colspan="3" style="border-bottom:1px solid #eff0f4;padding:5px">@Localizer["Payment fee"]</td>
                                                <td align="right" style="border-bottom:1px solid #eff0f4;padding:5px 16px 5px 5px">@CurrencyService.FormatCurrency(Model.PaymentFeeAmount)</td>
                                            </tr>
                                            <tr>
                                                <td align="right" colspan="3" style="border-bottom:1px solid #eff0f4;padding:5px">@Localizer["Shipping fee"]</td>
                                                <td align="right" style="border-bottom:1px solid #eff0f4;padding:5px 16px 5px 5px">@CurrencyService.FormatCurrency(Model.ShippingFeeAmount)</td>
                                            </tr>
                                            <tr>
                                                <td align="right" colspan="3" style="border-bottom:1px solid #eff0f4;padding:5px">@Localizer["Tax"]</td>
                                                <td align="right" style="border-bottom:1px solid #eff0f4;padding:5px 16px 5px 5px">@CurrencyService.FormatCurrency(Model.TaxAmount)</td>
                                            </tr>
                                            <tr>
                                                <td align="right" colspan="3" style="border-bottom:1px solid #eff0f4;padding:5px"><strong>@Localizer["Order Total"]</strong></td>
                                                <td align="right" style="border-bottom:1px solid #eff0f4;padding:5px 16px 5px 5px"><strong>@CurrencyService.FormatCurrency(Model.OrderTotal)</strong></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <p>@Localizer["Thank you!"]</p>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
</table>
